package com.unionx.unionxuf.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unionx.unionxuf.common.TransformerStr;
import com.unionx.unionxuf.entity.Projectinfo;
import com.unionx.unionxuf.service.ProjectInfoService;



@Controller
@RequestMapping(value="/pro")
public class LocalProinfo {

	@Autowired
	private ProjectInfoService pfservice;	
	
	@RequestMapping(value="/get/mx")
	@ResponseBody
	public Object getmx(String xiangmu){
		
		return pfservice.getmx(xiangmu);
	}
	
	@RequestMapping(value="/get/pr")
	@ResponseBody
	public Object getPr(String xiaofei,String xiangmu,String mingxi){
		
		return pfservice.getPr(xiaofei,xiangmu,mingxi);
	}
	
	
	@RequestMapping(value="/del")
	@ResponseBody
	public Object delPr(String xiaofei,String xiangmu,String cropid){
		
		return pfservice.delPr(xiaofei,xiangmu,cropid);
	}
	

	
	
	@RequestMapping(value="/selectpro")
	@ResponseBody
	public Object selectpro(String cropid){
		
		return pfservice.selectpro(cropid);
	}
	
	
	
	@RequestMapping(value="/insert/pro")
	@ResponseBody
	public Object insertPr(String xiaofei,String xiangmu,String sbc,String sbn,String cropid){

		Map<String,Object> map =  new HashMap<String,Object>();
		
		int k =0;
		String str1[] = xiaofei.split(",");
		String str2[] = xiangmu.split(",");
		String str3[] = sbc.split(",");
		String str4[] = sbn.split(",");
		
		
		if(str1.length>1){
			for(int i = 0;i<str1.length;i++){
				Projectinfo p=  new Projectinfo();
				p.setConsumeclass(str1[i]);
				p.setProjecttype(str2[i]);
				p.setProjectsub("");
				p.setPrice("");
				p.setSubjectcode(str3[i]);
				p.setSubjectname(str4[i]);
				p.setCropid(cropid);
				p.setIsbend("1");
				
				 k= pfservice.insertPr(p);
			}
		}else{
		
			Projectinfo p=  new Projectinfo();
			p.setConsumeclass(str1[0]);
			p.setProjecttype(str2[0]);
			p.setProjectsub("");
			p.setPrice("");
			p.setSubjectcode(str3[0]);
			p.setSubjectname(str4[0]);
			p.setCropid(cropid);
			p.setIsbend("1");
			k= pfservice.insertPr(p);
		}
		
		map.put("status", k);
		
		return map;
	}
}
